package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.sgb.capital.utils.ResolutionUtil;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemPackerFirstContentBinding;
import com.sgb.kjwl.databinding.ItemPackerFirstContentTitleBinding;
import com.sgb.kjwl.databinding.ItemPackerFirstForTwoContentBinding;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.utils.NumberConstant;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * @author : younghow
 * @date : 2021/9/6 11:33
 * description:
 */
public class PackersFirstContentForTwoAdapter extends BaseRecycleAdapter<AddressEntity> {


    public PackersFirstContentForTwoAdapter(Context context, List<AddressEntity> data) {
        super(context, R.layout.item_packer_first_for_two_content, data);
    }

    @Override
    public void convert(ItemViewHolder holder, AddressEntity entity) {
        holder.setBinding(BR.name, entity);
        ItemPackerFirstForTwoContentBinding binding = (ItemPackerFirstForTwoContentBinding) holder.getmBinding();
        if (entity.getName().length()<= NumberConstant.NUMBER_TWO){
            binding.tvPackerFirstContentName.setText(entity.getName());
        }else if (entity.getName().length()>NumberConstant.NUMBER_TWO && entity.getName().length()<=NumberConstant.NUMBER_FOUR){
            String name = entity.getName().substring(0,2) + "\n" + entity.getName().substring(2);
            binding.tvPackerFirstContentName.setText(name);
        }else {
            String name = entity.getName().substring(0,2) + "\n" + entity.getName().substring(2,4);
            binding.tvPackerFirstContentName.setText(name);
        }

        ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
        params.width = ResolutionUtil.getScreenWidth(context) / 5;
    }
}
